import request from '@/utils/request'
// import qs from 'qs'

// DNAT

// 获取列表
export function getDnatArray (params) {
  var data = fromData(params)
  return request({
    url: 'dnat/getDnatArray',
    method: 'post',
    data
  })
}

// 添加DNAT规则
export function addDnat (params) {
  var data = fromData(params)
  return request({
    url: 'dnat/addDnat',
    method: 'post',
    data
  })
}

// 删除DNAT规则
export function delDnat (params) {
  var data = fromData(params)
  return request({
    url: 'dnat/del_dnat',
    method: 'post',
    data
  })
}

// 编辑DNAT规则
export function editDnat (params) {
  var data = fromData(params)
  return request({
    url: 'dnat/editDnat',
    method: 'post',
    data
  })
}

// 清空DNAT规则
export function clearDnat (params) {
  var data = fromData(params)
  return request({
    url: 'dnat/clear_dnat',
    method: 'post',
    data
  })
}

// function fromData (params) {
//   var data = qs.stringify(params)
//   return data
// }

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
